//
//  RecentCell.m
//  SportSocial
//
//  Created by yull on 14/11/19.
//  Copyright (c) 2014年 yull. All rights reserved.
//

#import "RecentCell.h"
#import "UIView+Frame.h"
#import "UIColor+MethodExt.h"
#import "UIImageView+WebCache.h"

@implementation RecentCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self =[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        CGRect rect = CGRectMake(0, self.nameLabel.top + 2, 20, 20);
        self.sexImageView = [[UIImageView alloc] initWithFrame:rect];
        [self.contentView addSubview:self.sexImageView];
        
        self.unreadLabel = [[InForNumber alloc] initWithFrame:CGRectMake(100, self.timeLabel.bottom + 10, 0, 15)];
        self.unreadLabel.centerX = self.contentView.width- 30;
        [self.contentView addSubview:self.unreadLabel];
    }
    return self;
}

- (void)drawCellWithRecent:(ChatInfo *)recent
{
    [super drawCellWithRecent:recent];
    
    if (recent.infoType == ChatInfoTypePrivate) {
        NSString *imageName = recent.sex == SexTypeGirl ? @"female_icon" : @"male_icon";
        self.sexImageView.image = [UIImage imageNamed:imageName];
        
    }else if (recent.infoType == ChatInfoTypeGroup) {
        self.sexImageView.image = nil;
    }
    
    self.sexImageView.left = self.nameLabel.right + 3;
    
    if (recent.unReadCount > 0) {
        self.unreadLabel.hidden = NO;
        [self.unreadLabel InforNumberText: [NSString stringWithFormat:@"%d",recent.unReadCount]];
        self.unreadLabel.right = self.timeLabel.right;
    }else {
        self.unreadLabel.hidden = YES;
    }
}

- (UIEdgeInsets)layoutMargins
{
    return UIEdgeInsetsMake(0, self.nameLabel.left, 0, 0);
}
@end
